//
//  GCDDownView.m
//  DefendHealth
//
//  Created by UNOHACHA on 17/3/4.
//  Copyright © 2017年 iMacOne. All rights reserved.
//

#import "GCDDownView.h"
#import "Header.h"
@implementation GCDDownView

{
    
    UILabel * _timL;
}
- (instancetype)initWithFrame:(CGRect)frame {
    
    self = [super initWithFrame:frame];
    
    if (self) {
        
        self.backgroundColor = UIColorFromRGB(0x999999);
        
        UILabel * timL = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, CGRectGetMaxX(self.bounds), 120)];
        timL.center = self.center;
        _timL = timL;
        timL.font = [UIFont fontWithName:@"Helvetica-Bold" size:120];
        timL.textColor = kWhiteColor;
        timL.alpha = 0;
        timL.textAlignment = NSTextAlignmentCenter;
        [self addSubview:timL];
        
//        [self animationView];
        
    }
    
    return self;
    
}

- (void)animationViewBlock:(void (^)(void))endBlock {

    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
    
        [ToolUtil countDownWithTime:4 countDownBlock:^(int timeLeft) {
            
            _timL.text = NSString(@"%d", timeLeft);
            
            POPBasicAnimation *basicAnimation=[POPBasicAnimation animationWithPropertyNamed:kPOPViewAlpha];
            basicAnimation.fromValue=@(0);
            basicAnimation.toValue=@(1);
            
            POPSpringAnimation *begin = [POPSpringAnimation animationWithPropertyNamed:kPOPLayerPositionY];
            begin.springSpeed = 12;
            begin.springBounciness = 8;
            begin.fromValue=@(self.centerY-100);
            begin.toValue=@(self.centerY);
            
            [_timL.layer pop_addAnimation:begin forKey:@"timLLayerAnimation"];
            [_timL pop_addAnimation:basicAnimation forKey:@"timLAnimation"];
            
        } endBlock:^{
            
            if (endBlock) {
                endBlock();
            }
            
            [UIView animateWithDuration:0.3 animations:^{
                self.alpha = 0;
                
            } completion:^(BOOL finished) {
                [self removeFromSuperview];
            }];
        }];
    });
}



@end
